/*
 * @Descripttion:
 * @version:
 * @Author: 麦冬果果
 * @Date: 2021-03-31 13:30:02
 * @LastEditors: 麦冬果果
 * @LastEditTime: 2021-04-08 13:52:17
 */
package middlewares

import (
	"mdgg/app/admin/service/user_service"
	"mdgg/library/response"
	"mdgg/library/service"

	"github.com/gogf/gf/net/ghttp"
	"github.com/gogf/gf/util/gconv"
)

func Admin(r *ghttp.Request) {

	uid := user_service.GetLoginID(r)

	if uid == 0 {
		response.JsonExit(r, -401, "获取当前登录用户信息失败ctx,请刷新登录")
		//response.FailJson(true, r, "获取当前登录用户信息失败ctx,请刷新登录")
	}
	isSuperAdmin := false
	for _, v := range service.NotCheckAuthAdminIds {
		if gconv.Uint64(v) == uid {
			isSuperAdmin = true
			break
		}
	}
	r.SetCtxVar("admin_id", uid)
	r.SetCtxVar("is_super", isSuperAdmin)
	r.Middleware.Next()
}
